<template>
    <div>
        <h1>科室信息新增</h1>
        <hr>
        <br>
        <hr>
        <table class="table">
            <tbody>
                <tr>
                    <td>科室名称</td>
                    <td><input type="text" v-model="data.DepName"></td>
                </tr>

                <tr>
                    <td>科室人数</td>
                    <td><input type="text" v-model="data.DepNum"></td>
                </tr>

                <tr>
                    <td>科室描述</td>
                    <td>
                        <textarea v-model="data.DepMiao">

                        </textarea>
                    </td>
                </tr>

                <tr>
                    <td>创建日期</td>
                    <td><input type="date" v-model="data.DepDate"></td>
                </tr>
                <tr>
                    <td></td>
                    <td><input type="button" value="新增" @click="Add"></td>
                </tr>
            </tbody>
        </table>
    </div>
</template>

<script setup lang="ts">

import { ref } from 'vue';
import axios from 'axios';
import { useRouter } from 'vue-router';
const router = useRouter()
const data = ref({
    "DepId": 0,
  "DepName": "",
  "DepNum": "",
  "DepMiao": "",
  "DepDate": "",
  "DepIsDelete": true
})

const Add = ()=>{
    if(data.value.DepName=="耳科"){
        alert('科室名称不能重复')
        return
    }
    if(data.value.DepName=="眼科"){
        alert('科室名称不能重复')
        return
    }
    if(data.value.DepName=="脑科"){
        alert('科室名称不能重复')
        return
    }

    axios.post('https://localhost:7087/api/Depart/DepAdd',data.value).then(res=>{
        if(res.data>0){
            alert('新增成功');
            router.push({path:"/DepShow"})
        }
        else{
            alert('新增失败')
        }
    })
}



</script>

<style scoped>

</style>